package com.core.pagehelper.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.core.pagehelper.entity.PageBean;
import com.core.pagehelper.entity.UserInfor;
import com.core.pagehelper.service.PageHelperShowService;

@Controller
@RequestMapping("pagehelperShow")
public class PageHelperShowController {
	private static final Logger logger = Logger.getLogger(PageHelperShowController.class);
	
	@Resource
	private PageHelperShowService pageHelperShowService;
	
	@RequestMapping("show.do")
	@ResponseBody
	public PageBean<UserInfor> pageHelperShow(HttpServletRequest request,
			HttpServletResponse response){
		logger.info("-----show time!-----");
		PageBean<UserInfor> page = pageHelperShowService.showPage(request);
		logger.info("-----总条数-----:"+page.getTotal());
		return page;
	}
	
	@RequestMapping("insertBatch.do")
	public String insertMore(){
		logger.info("-----batch inserts start!-----");
		List<UserInfor> list = new ArrayList<UserInfor>();
		for (int i = 40; 40 <= i && i < 60; i++) {
			UserInfor user = new UserInfor();
			user.setUsername("bruce"+i);
			user.setPassword("10"+i);
			list.add(user);
		}
		int result = pageHelperShowService.batchInserts(list);
		logger.info("------成功插入：------"+result+"条数据");
		return "index";
	}
}
